home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.51 / xpk-kp / unit_xpk.p < prev    next >
Text File  |  1995-08-27  |  13KB  |  365 lines

  1.  
  2. { Unit:       Xpk
  3.   ~~~~~
  4.   Version:    V0.02 / 10.11.1994
  5.   ~~~~~~~~
  6.   What is it: Xpk.Library-Interface for KickPascal/MaxonPascal
  7.   ~~~~~~~~~~~
  8.   Copyright:  The interface is © & (P) 1994 by Janosh/NPL (J.Stötzer)
  9.   ~~~~~~~~~~  It's free 4 use and distribution.
  10.  
  11.               Xpk is © 1991 by C. Schneider & U.D. Mueller
  12.  
  13.   Contact:    J. Stötzer
  14.   ~~~~~~~~    An der Hasel 195
  15.               D-98527 Suhl
  16.               Germany
  17.  
  18.   Comment:    For sublibrary handling you'll need Unit XpkSub, which
  19.   ~~~~~~~~    belongs to this package.
  20.                                                                           }
  21. {*************************************************************************}
  22.  
  23.  
  24. Unit Xpk;
  25.  
  26. {$opt q}
  27.  
  28. INTERFACE
  29.  
  30. Uses Exec;
  31.  
  32. {$incl "utility/tagitem.h","utility/hooks.h"}
  33.  
  34. const XPKNAME = 'xpkmaster.library';
  35.  
  36.  
  37. {******************************************************************************
  38. *
  39. *      The packing/unpacking tags
  40. *
  41. *}
  42.  
  43. const XPK_TagBase = (TAG_USER+(ord('X')*256)+ord('P'));
  44.  
  45. {Caller must supply ONE of these to tell XpkPackFile where to get data from}
  46.  
  47. XPK_InName = (XPK_TagBase+$01);   {Name of a single data file}
  48. XPK_InFH = (XPK_TagBase+$02);     {File handle - read from current position}
  49. XPK_InBuf = (XPK_TagBase+$03);    {Unblocked buffer - must also supply InLen}
  50. XPK_InHook = (XPK_TagBase+$04);   {Callback Hook to get input data}
  51.  
  52. {Caller must supply ONE of these to tell XpkPackFile where to send data to}
  53.  
  54. XPK_OutName = (XPK_TagBase+$10);   {Write (or overwrite) this data file}
  55. XPK_OutFH = (XPK_TagBase+$11);    {File handle - write from current position on}
  56. XPK_OutBuf = (XPK_TagBase+$12);   {Unblocked buffer - must also supply OutBufLen}
  57. XPK_GetOutBuf = (XPK_TagBase+$13);{Master allocates OutBuf - ti_Data points to buffer pointer}
  58. XPK_OutHook = (XPK_TagBase+$14);  {Callback Hook to get output buffers}
  59.  
  60. {Other junk}
  61.  
  62. XPK_InLen = (XPK_TagBase+$20);        {len of data in input buffer}
  63. XPK_OutBufLen = (XPK_TagBase+$21);    {len of output buffer}
  64. XPK_GetOutLen = (XPK_TagBase+$22);    {ti_Data points to long to receive OutLen}
  65. XPK_GetOutBufLen = (XPK_TagBase+$23); {ti_Data points to long to receive OutBufLen}
  66. XPK_Password = (XPK_TagBase+$24);     {password for de/encoding}
  67. XPK_GetError = (XPK_TagBase+$25);     {ti_Data points to buffer for error message}
  68. XPK_OutMemType = (XPK_TagBase+$26);   {Memory type for output buffer}
  69. XPK_PassThru = (XPK_TagBase+$27);     {Bool: Pass through unrecognized formats}
  70. XPK_StepDown = (XPK_TagBase+$28);     {Bool: Step down pack method if necessary}
  71. XPK_ChunkHook = (XPK_TagBase+$29);    {Call this Hook between chunks}
  72. XPK_PackMethod = (XPK_TagBase+$2a);   {Do a FindMethod before packing}
  73. XPK_ChunkSize = (XPK_TagBase+$2b);    {Chunk size to try to pack with}
  74. XPK_PackMode = (XPK_TagBase+$2c);     {Packing mode for sublib to use}
  75. XPK_NoClobber = (XPK_TagBase+$2d);    {Don't overwrite existing files }
  76. XPK_Ignore = (XPK_TagBase+$2e);       {Skip this tag                  }
  77. XPK_TaskPri = (XPK_TagBase+$2f);      {Change priority for (un)packing}
  78. XPK_FileName = (XPK_TagBase+$30);     {File name in progress report}
  79. XPK_ShortError = (XPK_TagBase+$31);   {Output short error messages    }
  80. XPK_PackersQuery = (XPK_TagBase+$32); {Query available packers        }
  81. XPK_PackerQuery = (XPK_TagBase+$33);  {Query properties of a packer   }
  82. XPK_ModeQuery = (XPK_TagBase+$34);    {Query properties of packmode   }
  83. XPK_LossyOK = (XPK_TagBase+$35);      {Lossy packing permitted? def.=no}
  84.  
  85. XPK_FindMethod = XPK_PackMethod;
  86.  
  87. XPK_MARGIN = 256;
  88.  
  89.  
  90. {**************************************************************************
  91. *
  92. *     Message passed to InHook and OutHook
  93. *
  94. *}
  95.  
  96. type p_XpkIOMsg = ^XpkIOMsg;
  97.      XpkIOMsg = record
  98.        xiom_Type : long;     {Read/Write/Alloc/Free/Abort}
  99.        xiom_Ptr : ptr;       {The mem area to read from/write to}
  100.        xiom_Size : long;     {The size of the read/write }
  101.        xiom_IOError : long;  {The IoErr() that occurred }
  102.        xiom_Reserved : long; {Reserved for future use }
  103.        xiom_Private1 : long; {Hook specific, will be set to 0 by}
  104.        xiom_Private2 : long; {master library before first use}
  105.        xiom_Private3 : long;
  106.        xiom_Private4 : long;
  107.      end;
  108.  
  109. {The values for XpkIoMsg->Type}
  110. const
  111. XIO_READ = 1;
  112. XIO_WRITE = 2;
  113. XIO_FREE = 3;
  114. XIO_ABORT = 4;
  115. XIO_GETBUF = 5;
  116. XIO_SEEK = 6;
  117. XIO_TOTSIZE = 7;
  118.  
  119.  
  120.  
  121.  
  122.  
  123. {******************************************************************************
  124. *
  125. *
  126. *   The progress report interface
  127. *
  128. *}
  129.  
  130. type p_XpkProgress = ^XpkProgress;
  131.      XpkProgress = record
  132.        xp_Type : long;            {Type of report: start/cont/end/abort}
  133.        xp_PackerName : str;       {Brief name of packer being used  }
  134.        xp_PackerLongName : str;   {Descriptive name of packer being used }
  135.        xp_Activity : ptr;         {Packing/unpacking message  }
  136.        xp_FileName : str;         {Name of file being processed, if available}
  137.        xp_CCur : long;            {Amount of packed data already processed}
  138.        xp_UCur : long;            {Amount of unpacked data already processed }
  139.        xp_ULen : long;            {Amount of unpacked data in file }
  140.        xp_CF : long;              {Compression factor so far  }
  141.        xp_Done : long;            {Percentage done already  }
  142.        xp_Speed : long;           {Bytes per second, from beginning of stream}
  143.        xp_Reserved : array[0..7] of long; {For future use   }
  144.      end;
  145.  
  146. const
  147. XPKPROG_START = 1;
  148. XPKPROG_MID = 2;
  149. XPKPROG_END = 3;
  150.  
  151.  
  152.  
  153. {*****************************************************************************
  154. *
  155. *
  156. *       The file info block
  157. *
  158. *}
  159.  
  160. type p_XpkFib = ^XpkFib;
  161.      XpkFib = record
  162.        xf_Type : long;                    {Unpacked, packed, archive?  }
  163.        xf_ULen : long;                    {Uncompressed length         }
  164.        xf_CLen : long;                    {Compressed length           }
  165.        xf_NLen : long;                    {Next chunk len              }
  166.        xf_UCur : long;                    {Uncompressed bytes so far   }
  167.        xf_CCur : long ;                   {Compressed bytes so far     }
  168.        xf_ID : long;                      {4 letter ID of packer       }
  169.        xf_Packer : array[0..5] of byte;   {4 letter name of packer     }
  170.        xf_SubVersion : word;              {Required sublib version     }
  171.        xf_MasVersion :word;               {Required masterlib version  }
  172.        xf_Flags : long;                   {Password?                   }
  173.        xf_Head : array[0..15] of byte;    {First 16 bytes of orig. file}
  174.        xf_Ratio : long;                   {Compression ratio           }
  175.        xf_Reserved : array[0..7] of long; {For future use              }
  176.      end;
  177.  
  178. const
  179. XPKTYPE_UNPACKED  = 0;                {Not packed                  }
  180. XPKTYPE_PACKED   = 1;                 {Packed file                 }
  181. XPKTYPE_ARCHIVE   = 2;                {Archive                     }
  182.  
  183. XPKFLAGS_PASSWORD = 1;                {Password needed             }
  184. XPKFLAGS_SEEK   = 2;                  {Chunks are independent      }
  185. XPKFLAGS_NONSTD   = 4;                {Nonstandard file format     }
  186.  
  187. type p_XpkFH = ^XpkFH;
  188.      XpkFH = record
  189.        fib : XpkFib;
  190.        {Sum more private and not documented data...}
  191.      end;
  192.  
  193.  
  194. {******************************************************************************
  195. *
  196. *       The error messages
  197. *
  198. *}
  199.  
  200. const
  201. XPKERR_OK  = 0;
  202. XPKERR_NOFUNC  = -1;         {This function not implemented }
  203. XPKERR_NOFILES  = -2;        {No files allowed for this function }
  204. XPKERR_IOERRIN  = -3;        {Input error happened, look at Result2}
  205. XPKERR_IOERROUT  = -4;       {Output error happened, look at Result2}
  206. XPKERR_CHECKSUM  = -5;       {Check sum test failed  }
  207. XPKERR_VERSION  = -6;        {Packed file's version newer than lib's}
  208. XPKERR_NOMEM  = -7;          {Out of memory   }
  209. XPKERR_LIBINUSE  = -8;       {For not-reentrant libraries }
  210. XPKERR_WRONGFORM = -9;       {Was not packed with this library }
  211. XPKERR_SMALLBUF  = -10;      {Output buffer too small  }
  212. XPKERR_LARGEBUF  = -11;      {Input buffer too large  }
  213. XPKERR_WRONGMODE = -12;      {This packing mode not supported }
  214. XPKERR_NEEDPASSWD = -13;     {Password needed for decoding this file}
  215. XPKERR_CORRUPTPKD  = -14;    {Packed file is corrupt  }
  216. XPKERR_MISSINGLIB  = -15;    {Required library is missing }
  217. XPKERR_BADPARAMS  = -16;     {Caller's TagList was screwed up      }
  218. XPKERR_EXPANSION = -17;      {Would have caused data expansion  }
  219. XPKERR_NOMETHOD    = -18;    {Can't find requested method          }
  220. XPKERR_ABORTED     = -19;    {Operation aborted by user            }
  221. XPKERR_TRUNCATED = -20;      {Input file is truncated  }
  222. XPKERR_WRONGCPU    = -21;    {Better CPU required for this library}
  223. XPKERR_PACKED      = -22;    {Data are already XPacked  }
  224. XPKERR_NOTPACKED   = -23;    {Data not packed   }
  225. XPKERR_FILEEXISTS  = -24;    {File already exists  }
  226. XPKERR_OLDMASTLIB  = -25;    {Master library too old  }
  227. XPKERR_OLDSUBLIB   = -26;    {Sub library too old  }
  228. XPKERR_NOCRYPT     = -27;    {Cannot encrypt   }
  229. XPKERR_NOINFO      = -28;    {Can't get info on that packer }
  230. XPKERR_LOSSY  = -29;         {This compression method is lossy }
  231. XPKERR_NOHARDWARE = -30;     {Compression hardware required }
  232. XPKERR_BADHARDWARE = -31;    {Compression hardware failed }
  233. XPKERR_WRONGPW     = -32;    {Password was wrong   }
  234.  
  235.  
  236. XPKERRMSGSIZE  = 80;         {Maximum size of an error message }
  237.  
  238.  
  239.  
  240.  
  241.  
  242. {*****************************************************************************
  243. *
  244. *
  245. *     The XpkQuery() call
  246. *
  247. *}
  248.  
  249. type p_XpkPackerInfo = ^XpkPackerInfo;
  250.      XpkPackerInfo = record
  251.        xpi_Name : array[0..23] of char;        {Brief name of the packer         }
  252.        xpi_LongName : array[0..31] of char;    {Full name of the packer          }
  253.        xpi_Description : array[0..79] of char; {One line description of packer   }
  254.        xpi_Flags : long;    {Defined below                    }
  255.        xpi_MaxChunk : long; {Max input chunk size for packing }
  256.        xpi_DefChunk : long; {Default packing chunk size       }
  257.        xpi_DefMode : word;  {Default mode on 0..100 scale     }
  258.      end;
  259.  
  260. const
  261. XPKIF_PK_CHUNK   = $00000001;   {Library supplies chunk packing      }
  262. XPKIF_PK_STREAM  = $00000002;   {Library supplies stream packing     }
  263. XPKIF_PK_ARCHIVE = $00000004;   {Library supplies archive packing    }
  264. XPKIF_UP_CHUNK   = $00000008;   {Library supplies chunk unpacking    }
  265. XPKIF_UP_STREAM  = $00000010;   {Library supplies stream unpacking   }
  266. XPKIF_UP_ARCHIVE = $00000020;   {Library supplies archive unpacking  }
  267. XPKIF_HOOKIO     = $00000080;   {Uses full Hook I/O                  }
  268. XPKIF_CHECKING   = $00000400;   {Does its own data checking          }
  269. XPKIF_PREREADHDR = $00000800;   {Unpacker pre-reads the next chunkhdr}
  270. XPKIF_ENCRYPTION = $00002000;   {Sub library supports encryption     }
  271. XPKIF_NEEDPASSWD = $00004000;   {Sub library requires encryption     }
  272. XPKIF_MODES      = $00008000;   {Sub library has different modes     }
  273. XPKIF_LOSSY      = $00010000;   {Sub library does lossy compression  }
  274.  
  275.  
  276. type p_XpkMode = ^XpkMode;
  277.      XpkMode = record
  278.        xm_Next : p_XpkMode;    {Chain to next descriptor for ModeDesc list}
  279.        xm_Upto : long;         {Maximum efficiency handled by this mode  }
  280.        xm_Flags : long;        {Defined below                            }
  281.        xm_PackMemory : long;   {Extra memory required during packing     }
  282.        xm_UnpackMemory : long; {Extra memory during unpacking            }
  283.        xm_PackSpeed : long;    {Approx packing speed in K per second     }
  284.        xm_UnpackSpeed : long;  {Approx unpacking speed in K per second   }
  285.        xm_Ratio : word;        {CF in 0.1% for AmigaVision executable    }
  286.        xm_ChunkSize : word;    {Desired chunk size in K (!!) for this mode}
  287.        xm_Description : array[0..9] of char; {8 character mode description}
  288.      end;
  289.  
  290. const
  291. XPKMF_A3000SPEED = $00000001;   {Timings on A3000/25              }
  292. XPKMF_PK_NOCPU   = $00000002;   {Packing not heavily CPU dependent}
  293. XPKMF_UP_NOCPU   = $00000004;   {Unpacking... (i.e. hardware modes)}
  294.  
  295.  
  296. MAXPACKERS = 100;
  297.  
  298.  
  299. type p_XpkPackerList = ^XpkPackerList;
  300.      XpkPackerList = record
  301.        xpl_NumPackers : long;
  302.        xpl_Packer : array[1..MAXPACKERS*6] of byte;
  303.      end;
  304.  
  305.  
  306. {*****************************************************************************
  307. *
  308. *
  309. *     The XpkOpen() type calls
  310. *}
  311.  
  312.  
  313. const
  314. XPKLEN_ONECHUNK = $7fffffff;
  315.  
  316.  
  317. var XpkMasterBase : ptr;
  318.  
  319.  
  320. Library XpkMasterBase:
  321.   {-30 : XpkPackerInfo;   do not use}
  322.   -36 : function XpkExamine(a0:p_XpkFib;a1:p_TagItem):long;
  323.   -42 : function XpkPack(a0:p_TagItem):long;
  324.   -48 : function XpkUnpack(a0:p_TagItem):long;
  325.   -54 : function XpkOpen(a0:ptr;a1:p_TagItem):long;     {a0=xFH**}
  326.   -60 : function XpkRead(a0:p_XpkFH;a1:ptr;d0:long):long;  {a0=xFH*}
  327.   -66 : function XpkWrite(a0:ptr;a1:ptr;d0:long):long;
  328.   -72 : function XpkSeek(a0:ptr;d0,d1:long):long;
  329.   -78 : function XpkClose(a0:ptr):long;
  330.   -84 : function XpkQuery(a0:p_TagItem):long;
  331. end;
  332.  
  333. function XTag(n:long):long;
  334. function Xpk_Open(fh:p_XpkFH;ti:p_TagItem):long;
  335.  
  336.  
  337. IMPLEMENTATION
  338.  
  339. function XTag;
  340.  
  341. begin
  342.   XTag:=XPK_TagBase+n;
  343. end;
  344.  
  345. function Xpk_Open;
  346.  
  347. var pfh : ptr;
  348.  
  349. begin
  350.   pfh:=^fh;
  351.   Xpk_Open:=XpkOpen(pfh,ti);
  352. end;
  353.  
  354. end.
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.